package com.wnxy.d_syn;
// 死锁演示：多个线程互相持有对方的锁
public class DeadLock {

    private static Object objA = new Object();
    private static Object objB = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            synchronized (objA) {
                System.out.println("AAAAA");
                synchronized (objB) {
                    System.out.println("BBBBB");
                }
            }
        },"t1");

        Thread t2 = new Thread(()->{
            synchronized (objB) {
                System.out.println("CCCCC");
                synchronized (objA) {
                    System.out.println("DDDDD");
                }
            }
        },"t2");

        t1.start();
        t2.start();
    }
}
